/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exercicio.lista3;

import java.util.Random;

/**
 *
 * @author afonso
 */
public class Questao2 {

    public static void main(String args[]) {
        letraA();
        letraB();
        letraC();
    }

    public static void letraA() {
        int numExp = 10000;
        int qtdeLote = 500;
        int soma = 0;

        Random r = new Random();

        for (int c = 0; c < numExp; c++) {
            for (int peca = 0; peca < qtdeLote; peca++) {
                if (r.nextGaussian() <= -0.8333) soma++;
            }
        }

        double media = (double) soma / numExp;

        System.out.println("a) Quantidade = " + Math.floor(media));
    }

    public static void letraB() {
        int numExp = 1000;
        int cont = 0;

        Random r = new Random();

        for (int c = 0; c < numExp; c++) {
            if (r.nextGaussian() > 0.4166) cont++;
        }

        double p = (double) cont / numExp;
        System.out.println("b) Probabilidade = " + p);
    }

    public static void letraC() {
        int numExp = 10000;
        int qtdeLote = 500;
        int cont = 0;

        Random r = new Random();

        for (int c = 0; c < numExp; c++) {
            int qtdPecasRuins = 0;
            for (int peca = 0; peca < qtdeLote; peca++) {
                if (r.nextGaussian() > 1.666) qtdPecasRuins++;
                if (qtdPecasRuins > 20) {
                    cont++;
                    break;
                }
            }
        }

        double p = (double) cont / numExp;

        System.out.println("c) Probabilidade = " + p);
    }
}
